<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/font.css">
        <link rel="stylesheet" href="<%=basePath %>leyuiyc/css/xadmin.css">
        <script src="<%=basePath %>leyuiyc/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=basePath %>leyuiyc/js/xadmin.js"></script>
		<style>
		    /* body{overflow-y: scroll;} */ /* 禁止刷新后出现横向滚动条 */
		    /* .layui-table-body .layui-table,.layui-table-header .layui-table{width: 100%;}
			.layui-table-body.layui-table-main .layui-table-cell,.layui-table-header .layui-table-cell{white-space: pre-wrap;word-wrap: break-word; word-break: break-all; height: auto;} */
		</style>
        <script src="<%=basePath %>leyuiyc/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=basePath %>leyuiyc/js/xadmin.js"></script>
		
    </head>
    
    <body>
        
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="baleGoodsId" placeholder="请输入打包商品id" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="baleGoodName" placeholder="请输入打包商品名" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block" >
                                    <select name="status">
                                        <option value="">商品状态</option>
                                        <option value="0">下架</option>
                                        <option value="1">上架</option>
                                        </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form" id="test" lay-filter="test">
                           </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    
    
    <script>
			layui.use(['table','form','jquery','layer'], function(){
			  var table = layui.table;
			  var layer = layui.layer,
			  form = layui.form ;
			  table.render({
			    elem: '#test'
			    ,url:'selectBaleGoods.do'
			    ,width: 'auto'
			    ,height: 720
			    ,method: 'post'
			    ,toolbar: '#toolbarDemo'
			    ,title: '订单信息表'
			    ,totalRow: true
			    ,page: true
			    ,cols: [[
			      {type:'checkbox', fixed: 'left'}
			      ,{field:'baleGoodsId', width:130, title: '打包商品id', sort: true, fixed: 'left'}
			      ,{field:'commonGoodsId', width:130, title: '对应公共商品id'}
			      ,{field:'baleGoodsPrice', width:130, title: '打包对应公共商品价格'}
			      ,{field:'status', width:80, title: '商品状态',templet:'#state'}
			      ,{field:'awardedIntegral', width: 130, title: '赠送积分'}
			      ,{field:'integralBuy', width:130, title: '是否可积分兑换', sort: true,templet:'#integralBuy'}
			      ,{field:'goodsExchIntegral', width:130, title: '兑换所需积分'}
			      ,{field:'shippingFee', width:130, title: '运费'}
			      ,{field:'goodsRefund', width:130, title: '是否可以退货',templet:'#goodsRefund'}
			      ,{field:'returnFee', width: 130, title: '退货费用'}
			      ,{field:'baleGoodName', width:130, title: '打包商品名称' }
			      ,{field:'baleGoodPrice', width:130, title: '打包商品价格', sort: true}
			      ,{field:'baleAmount', width:130, title: '打包商品数量'}
			      ,{field:'balePresaleNum', width:130, title: '打包商品预售数量'}
			      ,{field:'baleGoodValidity', width: 130, title: '打包商品有效期'}
			      ,{field:'picpath', width:130, title: '打包商品图片路径', sort: true}
			      ,{field:'thumbPicpath', width:130, title: '打包商品缩略图片路径'}
			      ,{field:'createUserId', width:130, title: '创建人id'}
			      ,{field:'createUserName', width:130, title: '创建人名称'}
			      ,{field:'createDate', width:130, title: '创建时间'}
			      ,{field:'', width:270, title: '操作', fixed: 'right',toolbar:'#operation'}
			    ]]
			    ,even:true
			    ,skin: 'row' //表格风格
                ,limits:[10,20,30,40,50]
			    ,limit: 20 //每页默认显示的数量
			  });
			  //数据筛选
		        form.on('submit(search)',function(data){
		           // console.log(00000+data);
		            //执行重载
		            table.reload('test', {
		                where:data.field,
		                	page : {
								curr : 1 //从第一开始查看
						}
		            });
		            return false;
		        });
    		//批量删除时
    		table.on('toolbar(test)', function(obj) {
    			var checkStatus = table.checkStatus(obj.config.id);
    			switch (obj.event) {
    			case 'delAll':
    				var data = checkStatus.data;
    				var baleGoodsId = "";
    				for (var i = 0; i < data.length; i++) {
    					baleGoodsId += data[i].baleGoodsId + ",";
    				}
    				layer.confirm('真的删除行么', {
    					btn : [ '确定', '取消' ] //按钮
    				}, function(index) {
    					AJAX("deleteBaleGoods.do", baleGoodsId)
    					layer.msg('删除成功', {
    						icon : 1
    					});
    					table.reload('test', {
    						page : {
    							curr : 1 //从第一开始查看
    						}
    					});
    				}, function(index) {
    					layer.close(index);
    				})
    
    				break;
    			case 'addBaleGoods':
    				layer.open({
    					type : 2,
    					title : '增加打包商品',
    					maxmin : true,
    					area : [ '1400px', '750px' ], //弹出框大小
    					content : "goBaleGoods-addcp.do",
    					end : function() {}
    				});
    				break;
    			}
    		});
    		table.on('tool(test)', function(obj) {
    			var data = obj.data;
    			if (obj.event === 'delete') {
    				layer.confirm('真的删除行么', function(index) {
    					$.ajax({
    						url : "deleteBaleGoodsOne.do?baleGoodsId=" + data.baleGoodsId,
    						method : "post",
    						dataType : "json",
    						contentType : "application/json;charset=utf-8",
    						success : function(data) {
    							if (data != null) {
    								layer.msg('删除成功', {
    									icon : 1
    								});
    								return;
    							}
    
    							return;
    						}
    					})
    					obj.del();
    					layer.close(index);
    				});
    			} else if (obj.event === 'modify') {
    				var url = "goModify.do?baleGoodsId=" + data.baleGoodsId;
    				console.log(url);
    				layer.open({
    					type : 2,
    					title : '修改打包商品',
    					maxmin : true,
    					area : [ '1500px', '750px' ], //弹出框大小
    					content : url,
    					end : function() {}
    				});
    			}
    		});
    	});
    
    	//封装AJAX请求
    	function AJAX(url,data){
		       		$.ajax({
                    	url:url,
                    	method:"post",
                    	dataType:"json",
                    	data:data,
                    	contentType:"application/json;charset=utf-8",
                    	success:function(data){
                    		if(data != null){
                    			ayer.msg('删除成功', {icon: 1});
                    			return;
                    		}
                    		
                    		return;
                    	}
                    	})
		       } 
			
	</script>
	<script type="text/html" id="state">	
	   {{#  if(d.status == "0") {  }}
			<font color="#00ff00">下架</font>
		{{#  } else if(d.status == "1") {  }}
			<font color="#ff0000">上架</font>
		{{#  }  }}
    </script>
    <script type="text/html" id="integralBuy">	
	   {{#  if(d.receiptMethod == "0") {  }}
			<font color="#99CC66">否</font>
		{{#  } else if(d.receiptMethod == "1") {  }}
			<font color="#00FF00">是</font>
		{{#  }  }}
    </script>
    <script type="text/html" id="goodsRefund">	
	   {{#  if(d.goodsRefund == "0") {  }}
			<font color="#99CC66">否</font>
		{{#  } else if(d.goodsRefund == "1") {  }}
			<font color="#00FF00">是</font>
		{{#  }  }}
    </script>
    <script type="text/html" id="operation">
		<a lay-event="modify"><button class="layui-btn layui-btn-normal" ><i class="layui-icon">&#xe642;</i>修改打包商品</button></a>	
	    <a lay-event="delete"><button type="button" class="layui-btn layui-btn-danger"><i class="layui-icon">&#xe640;</i>删除打包商品</button></a>
    </script>
	<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
       <button lay-event="addBaleGoods" class="layui-btn" ><i class="layui-icon"></i>增加打包商品</button>
       <button  lay-event="delAll"  class="layui-btn layui-btn-danger"><i class="layui-icon">&#xe640;</i>批量删除打包商品</button>
    </div>
</script>
</html>
